document.querySelector('.login-form')
    .addEventListener('submit', function (event) {
        event.preventDefault();
        const url = '/api/login';
        const name = xss(document.querySelector('input[name="name"]').value);
        const schoolNumber = xss(document.querySelector('input[name="schoolNumber"]').value);

        fetch(`${url}?name=${name}&schoolNumber=${schoolNumber}`, {
            method: 'get'
        })
            .then((res) => {
                return res.json();
            })
            .then((res) => {
                if (res.ok) {
                    localStorage.setItem('token', res.token);
                    window.location.href = '/html/topic/answer.html';
                } else {
                    alert(res.msg);
                }
            });
    });